package com.jiliason.segmentation.doMain.serviceModel;

import com.jiliason.segmentation.doMain.AbstractService;
import com.jiliason.segmentation.entity.address.FullAddressOutPojo;
import com.jiliason.segmentation.entity.SegmentInputPojo;

import java.util.List;

public abstract class SegmentModelProc<T> extends AbstractService<SegmentInputPojo> {

    protected SegmentModelProc(String serviceTag, List<String> serviceId) {
        super(serviceTag, serviceId);
    }

    @Override
    public String handle(SegmentInputPojo input) throws Exception {
        return model(input);
    }

    /**
    * @description _地址分词业务模版
    * @param input input
    * @return String
    * @date 2023/12/22
    * @author sjy
    */
    public String model(SegmentInputPojo input) throws Exception {
        // input合规性check
        if (invalidInput(input)) return FullAddressOutPojo.builder().build().invalidResponse(input);
        // 地址分词
        T segRes = exeSegment(input);
        // 返回分词结果
        return buildResponse(input, segRes);
    }
    /**
     * @description _check Input
     * @param input input
     * @return boolean
     * @date 2023/12/22
     * @author sjy
     */
    protected abstract boolean invalidInput(SegmentInputPojo input);

    /**
    * @description _
    * @param input input
    * @return 分词结果java对象
    * @date 2023/12/22
    * @author sjy
    */
    protected abstract T exeSegment(SegmentInputPojo input) throws Exception;

    /**
     * @description _编辑response
     * @param input,segRes input 和 分词结果
     * @return String json
     * @date 2023/12/22
     * @author sjy
     */
    protected abstract String buildResponse(SegmentInputPojo input, T segRes);


}
